#include "stdafx.h"
#include "GameLog.h"

//CTOR & DTOR
GameLog::GameLog(bool activateLog, std::string fileName)
{
	std::cout << "Creation du GameLog" << std::endl;

	this->_logActivated = activateLog;
	this->_logFileName = fileName;

	if (this->_logActivated)
	{
		_logFileStream = new std::ofstream(_logFileName, std::ios::app);

		if (_logFileStream->is_open())
		{
			*_logFileStream << "###################################" << std::endl;
			*_logFileStream << "###	NEW SESSION STARTED			###" << std::endl;
			*_logFileStream << "###	Date: jj/mm/aaaa hh:mm:ss	###" << std::endl;
			*_logFileStream << "###	Session type : DEBUG		###" << std::endl;
			*_logFileStream << "###################################" << std::endl;
		}
		else
		{
			std::cout << "Le fichier de log n'a pas pu etre ouvert." << std::endl; 
		}
	}
}


GameLog::~GameLog(void)
{
	std::cout << "Destruction du GameLog" << std::endl;

	if (_logFileStream->is_open())
	{
		*_logFileStream << "### Session ended at jj/mm/aaaa hh:mm:ss ###" << std::endl;
		_logFileStream->close();
	}
	delete _logFileStream;
}


//METHODS
bool				GameLog::LogFileExist(std::string file)
{

	return true;
}

bool				GameLog::CreateLogFile(std::string file)
{
	return true;
}

bool				GameLog::SetLogLevel(GameLog::LogLevel)
{
	return true;
}

GameLog::LogLevel	GameLog::GetLogLevel()
{
	return	this->_logLevel;
}

std::string			GameLog::GetLogFilePath() const
{
	return this->_logFileName;
}

bool				GameLog::AddToLog(GameLog::LogLevel logLevel, std::string error, std::string location, std::string parameters)
{
	if (_logFileStream->is_open()) //si le fichier est ouvert
	{
		switch (logLevel)
		{
		case G_NOTICE:
			{
				*_logFileStream << "[Time][Notice]	" << error << " at " << location << " with " << parameters << std::endl;
			}break;
		case G_WARNING:
			{
				*_logFileStream << "[Time][Warning]	" << error << " at " << location << " with " << parameters << std::endl;
			}break;
		case G_FAILURE:
			{
				*_logFileStream << "[Time][Failure]	" << error << " at " << location << " with " << parameters << std::endl;
			}break;
		case G_ERROR:
			{
				*_logFileStream << "[Time][Error]	" << error << " at " << location << " with " << parameters << std::endl;
			}break;
		case G_CRITICAL:
			{
				*_logFileStream << "[Time][Critical]	" << error << " at " << location << " with " << parameters << std::endl;
			}break;
		}
	}
	else
	{
		std::cout << "Impossile d'ajouter l'erreur dans le fichier de log." << std::endl;
	}

	return true;
}